package test;

import java.util.Random;

//如何获取数组中的随机索引
//int[]arr={1,2,3,4,5}
/*Random r = new Random();
int randomindex = r,nextInt(arr.length);
System.out.println(randomindex);
 */

public class test5 {
    public static void main(String[] args) {
    int []arr={1,2,3,4,5};
    Random rand = new Random();
        for (int i = 0; i < arr.length; i++) {
            int random = rand.nextInt(arr.length);
            int temp = arr[random];
            arr[random] = arr[i];
            arr[i] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
